﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpPerfLoad
{
    class ThreadSafeList<T> : IEnumerable<T>
    {
        List<T> list = new List<T>();

        public void LockRemove(T value)
        {
            lock (list)
            {
                list.Remove(value);
            }
        }

        public List<T> LockRead()
        {
            lock (list)
            {
                return list.ToList();
            }
        }
        public int LockAdd(T value)
        {
            lock (list)
            {
                list.Add(value);
                return list.Count;
            }
        }

        public int Count
        {
            get
            {
                lock (list)
                {
                    return list.Count;
                }
            }
        }

        public IEnumerator<T> GetEnumerator()
        {
            return LockRead().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)LockRead()).GetEnumerator();
        }
    }
}
